@extends('admin::layouts.master')
@section('title')
    编辑权益
@endsection
@section('tab')
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" >
                    {{csrf_field()}}
                    {{hi_form_hidden('id',$info->id)}}
                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            <span class="x-red">*</span>banner名称</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <input type="text" name="title" lay-verify="required" value="{{$info->title}}" autocomplete="off" class="layui-input" placeholder="请输入banner名称"></div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">类型</label>
                        <div class="layui-input-inline">
                        <select lay-filter="type" name="type">
                            <option value="">请选择类型</option>
                            <option value="1" @if( $info->type == 1 ) selected="" @endif >小程序-首页-banner图</option>
                            <option value="3" @if( $info->type == 3 ) selected="" @endif >用户端-道路救援banner图</option>
                            <option value="4" @if( $info->type == 4 ) selected="" @endif >用户端-首页-活动主页banne</option>
                            <option value="6" @if( $info->type == 6 ) selected="" @endif >用户端-年检维修主页</option>
                            <option value="5" @if( $info->type == 5 ) selected="" @endif >商户端-APP引导页</option>
                        </select>
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="L_alias" class="layui-form-label">
                            <span class="x-red">*</span>banner图片</label>
                        <div class="layui-input-inline">
                            @if( $info->img )
                                <img class="layui-upload-img upload_img" src="{{$info->img_msg}}" height="100" width="150">
                                <input type="hidden" name="img" value="{{$info->img}}" lay-verify="pic_log" id="img_url">
                            @else
                                <img class="layui-upload-img upload_img" src="admin/images/bg.png" height="100" width="150">
                                <input type="hidden" name="img" value="" lay-verify="pic_log" id="img_url">
                            @endif
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            链接地址</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <input type="text" name="link_url"  autocomplete="off" value="{{$info->link_url}}" class="layui-input" placeholder="http:://www.****.com">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="username" class="layui-form-label">
                            排序</label>
                        <div class="layui-input-inline" style="width: 300px;">
                            <input type="number" max="255" name="sort" autocomplete="off" value="{{$info->sort}}" class="layui-input" placeholder="请输入排序号">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label for="L_repass" class="layui-form-label"></label>
                        <button class="layui-btn" lay-filter="btn_edit" lay-submit="">确认</button>
                    </div>
                </form>
            </div>
        </div>

@endsection

@section('tab_js')
    <script>

        layui.use(['form', 'layer', 'jquery'], function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;

            //监听提交
            form.on('submit(btn_edit)', function (data) {

                if( !data.field.img){
                    layer.msg("请上传banner图片", {time: 1000, icon: 5}); return false;
                }

                $.ajax({
                    url: js_url('admin-banner-update'),
                    type: 'post',
                    data: data.field,
                    dataType: "json",
                    success: function (result) {
                        if (result.state === 0) {
                            layer.msg("编辑成功", {time: 500, icon: 6}, function () {
                                //关闭当前frame
                                xadmin.close();
                                // 可以对父窗口进行刷新
                                xadmin.father_reload();
                            });
                        } else {
                            layer.msg(result.msg, {time: 2000, icon: 5});
                        }
                    }
                });
                return false;

            });


        });
    </script>
@endsection